import { UPDATEPAGEJOBCOLLECTION } from '../types/pagejobcollection'
import { createAction } from 'redux-actions'
import { getCollectionList } from '../../../../service/archive-operate-controller'
import { calcTimeHeader, formatTime } from '../../../../util/lodashmin/formatDate'

export const DOREQUESTJOBCOLLECTION = createAction(UPDATEPAGEJOBCOLLECTION, payload => {
  return new Promise(resolve => {
    getCollectionList().then(({ data: { data: entry, code } }) => {
      // 岗位收藏
      if (code === 200) {
        try {
          let list = []
          entry.map(data => {
            let distance = data.distance ? `${(data.distance / 1000).toFixed(2)}km` : ''
            list.push({
              collection_id: data.collection_id,
              id: data.id,
              postId: data.postId,
              resumeCount: data.resumeCount,
              viewCount: data.resumeCount,
              extra1: data.extra1,
              isOld: data.isOld,
              name: data.name,
              type: data.type,
              salary: data.salary,
              category: data.category,
              workPlace: data.postWorkLocations,
              // workContent: basicInfo.workContent,
              settlementMethod: data.settlementMethod,
              companyId: data.companyId,
              // practiceLabel: basicInfo.practiceLabel,
              isFast: data.isFast,
              date: data.gmtCreate ? calcTimeHeader(new Date(formatTime(data.gmtCreate)).getTime()) : '',
              distance
            })
          })
          resolve({
            dataSource: list
          })
        } catch (e) {
          resolve({
            dataSource: []
          })
        }
      } else {
        resolve({
          dataSource: []
        })
      }
    })
  })
})
